package adminLoginPack;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


public class userAdminShowAction extends Action {
 
 
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
 
       String mappingValue  ="";
       String userName = "";
       String password = "";
       String method = "";
       String addUsrMethod = "";
       boolean admin = false;
       String userId = null;
       
       String forwardPage = "authfailed";
       
       try{
    	   
    	   userName = (String)request.getParameter("userId");
           password = (String)request.getParameter("password");
           method = null != request.getParameter("methodName")?(String)request.getParameter("methodName"):"";
           
           String adminValue = null != request.getParameter("admin")?(String)request.getParameter("admin"):"N";
           
           addUsrMethod= null != request.getParameter("method123")?(String)request.getParameter("method123"):"";
           
           userId= null != request.getParameter("userId")?(String)request.getParameter("userId"):"";
           
           FemaUtilAuthenticate femaUtil = new FemaUtilAuthenticate();
			  
			  boolean isUserExist = femaUtil.isUserExist(request, response,userId);
			  if(!isUserExist){
				  forwardPage =  "authfailed";
			  }
           
           
           
           if(!"".equals(method) && "showAdminPage".equals(method)){
        	   if(!"".equals(addUsrMethod) && addUsrMethod.equals("Articles")){
        		   request.setAttribute("showPageForAdmin", "AdminArticles.jsp");
        		   request.setAttribute("userId", userId);
        		   
        	   }else if(!"".equals(addUsrMethod) && addUsrMethod.equals("CaseLaws")){
        		   request.setAttribute("showPageForAdmin", "AdminCaseLaws.jsp");
        	   }else if(!"".equals(addUsrMethod) && addUsrMethod.equals("Circulars")){
        		   request.setAttribute("showPageForAdmin", "AdminCircular.jsp");
        	   }else if(!"".equals(addUsrMethod) && addUsrMethod.equals("MasterCirculars")){
        		   request.setAttribute("showPageForAdmin", "AdminCircular.jsp");
        	   }else if(!"".equals(addUsrMethod) && addUsrMethod.equals("Notifications")){
        		   request.setAttribute("showPageForAdmin", "AdminNotification.jsp");
        	   }else if(!"".equals(addUsrMethod) && addUsrMethod.equals("PressNotes")){
        		   request.setAttribute("showPageForAdmin", "AdminPressNotes.jsp");
        	   }else if(!"".equals(addUsrMethod) && addUsrMethod.equals("FAQ")){
        		   request.setAttribute("showPageForAdmin", "AdminFAQ.jsp");
        		   
        	   }else if(!"".equals(addUsrMethod) && addUsrMethod.equals("Definitions")){
        		   request.setAttribute("showPageForAdmin", "AdminDefinitions.jsp");
        		   
        	   }else if(!"".equals(addUsrMethod) && addUsrMethod.equals("UploadAnswers")){
        		   request.setAttribute("showPageForAdmin", "Upload.jsp");
        		   
        	   }else if(!"".equals(addUsrMethod) && addUsrMethod.equals("UploadProperties")){
        		   request.setAttribute("showPageForAdmin", "Upload.jsp");
        		   
        	   }
        	   
        	   request.setAttribute("userId", userId);	   
               forwardPage = "adminSuccess";
           }
           request.setAttribute("userId", userId);	   
           
      
       }catch(Exception e){
    	   e.printStackTrace();
       }
       
      
       
       
       return mapping.findForward(forwardPage);
 
    }
 
}


